package com.apimanage.common.config;

import com.apimanage.common.utils.JwtTokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * JWT配置类
 * 用于在Spring应用启动时初始化统一的JwtTokenUtil工具类
 *
 * @author API管理平台
 */
@Configuration
public class JwtConfig implements InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(JwtConfig.class);

    private final JwtProperties jwtProperties;

    @Autowired
    public JwtConfig(JwtProperties jwtProperties) {
        this.jwtProperties = jwtProperties;
    }

    @Override
    public void afterPropertiesSet() {
        // 在Spring容器初始化时，初始化统一的JwtTokenUtil工具类
        logger.info("开始初始化统一的JWT工具类");
        JwtTokenUtil.initialize(jwtProperties);
        logger.info("统一的JWT工具类初始化完成");
    }
}